package com.juno.cafenoa.cryptic;

import java.io.UnsupportedEncodingException;

import android.util.Log;


public class CryptCore {
	
	public CryptCore() {}
	
	public String Decryption(String value, String key) {
		return DecryptKey(value, key);
	}
	
	public String Encryption(String value, String key) {
		return EncryptKey(value, key);
	}
	
	private String DecryptKey(String value, String key) {
		try {			
			SeedCipher chiper = new SeedCipher();
			byte[] deBuffer = Base64.decode(value, Base64.DEFAULT);
			String decryptRe = chiper.decryptAsString(deBuffer, key.getBytes(), "UTF-8");
			return decryptRe.trim();
		} catch (UnsupportedEncodingException e) {
			Log.e("Decrypt", e.toString(), e);
		} catch (Exception e) {
			Log.e("Decrypt", e.toString(), e);
		}
		return null;
	}
	
	private String EncryptKey(String value, String key) {
		try {
			SeedCipher chiper = new SeedCipher();
			byte[] enBuffer = Base64.encode(chiper.encrypt( value , key.getBytes( ) , "UTF-8" ), Base64.URL_SAFE);
			return new String( enBuffer ).trim();
		} catch (UnsupportedEncodingException e) {
			Log.e("Encrypt", e.toString(), e);
		} catch (Exception e) {
			Log.e("Encrypt", e.toString(), e);
		}
		return null;
	}
}
